package com.gxa.order.controller;

import com.gxa.common.commons.JsonResult;
import com.gxa.common.commons.R;
import com.gxa.common.utils.FileUtils;
import com.gxa.order.pojo.Consult;
import com.gxa.order.service.ConsultService;
import org.omg.CosNaming.IstringHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import sun.rmi.server.InactiveGroupException;

import javax.servlet.http.HttpServletRequest;
import javax.xml.transform.Result;
import java.lang.reflect.Array;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/consult")
@Component
public class ConsultController {

    @Autowired
    private ConsultService consultService;
//查询预约订单所有接口
    @GetMapping("/findConsultList")
    public Map findConsultList(Integer currentPage,Integer pageSize){
        return consultService.findConsultList(currentPage,pageSize);
    }
//新增后端录入
    @PostMapping("/addConsult")
    public R addConsult(@RequestBody Consult consult){
        return consultService.addConsult(consult);
    }

    /**
     * 查询待沟通所有预约订单接口
     * @param currentPage
     * @param pageSize
     * @param status
     * @return
     */
    @GetMapping("/findCommunicateList")
    public JsonResult findCommunicateList(Long currentPage, Long pageSize, Integer status){
        return consultService.findCommunicateList(currentPage,pageSize,status);
    }

    /**
     * 查询沟通中所有预约订单接口
     * @param currentPage
     * @param pageSize
     * @param status
     * @return
     */
    @GetMapping("/findCentreList")
    public JsonResult findCentreList(Long currentPage, Long pageSize, Integer status){
        return consultService.findCentreList(currentPage,pageSize,status);
    }

    /**
     * 查询线索池所有预约订单接口
     * @param currentPage
     * @param pageSize
     * @param status
     * @return
     */
    @GetMapping("/findThreadList")
    public JsonResult findThreadList(Long currentPage, Long pageSize, Integer status){
        return consultService.findThreadList(currentPage,pageSize,status);
    }

    /**
     * 修改状态为无效客户接口
     */
    @PostMapping("/updateClaimByStatus")
    public Map updateClaimByStatus(@RequestBody  Consult consult){
        return consultService.updateClaimByStatus(consult);
    }

    /**
     * 根据用户姓名，手机搜索接口
     */
    @GetMapping("/queryConsult")
    @ResponseBody
    public JsonResult queryConsult(Integer currentPage,Integer pageSize,String condition){
        return consultService.queryConsult(currentPage,pageSize,condition);
    }
    /**
     * 根据服务类型搜索预约订单
     */
    @GetMapping("/queryConsultf")
    @ResponseBody
    public JsonResult queryConsultf(Integer currentPage,Integer pageSize,Integer typeOfService){
        return  consultService.queryConsultf(currentPage,pageSize,typeOfService);
    }
    /**
     * 添加图片
     */
    @PostMapping("/updateStatusByImg")
    public R updateStatusByImg(MultipartFile file, HttpServletRequest request) {
        String s = FileUtils.fileUpload("/uploaddata",file,request);
        R r = new R();
        if (s!=null && s!=""){
            r.setCode(200);
            r.setMsg("添加成功");
            r.setData(s);
        }else {
            r.setCode(500);
            r.setMsg("图片上传失败");
        }
        return r;
    }

    /**
     * 新增更进内容接口(修改)
     * @param consult
     * @return
     */
    @PostMapping("/updateContent")
    public R updateContent(@RequestBody Consult consult){
            return consultService.updateContent(consult);
    }
    /*
    批量修改
     */
    @PostMapping("/updateCounselors")
    public R updateCounselors(@RequestBody HashMap map){

       return consultService.updateCounselors(map);
    }
    /*
    App端新增预定咨询
 */
    @PostMapping("/addAppContent")
    public R addAppContent(@RequestBody Consult consult){
        return consultService.addAppContent(consult);
    }
    /*
    无效客户修改状态为沟通中的认领
 */
    @PostMapping("/updateStatusByClaim")
    public R updateStatusByClaim(@RequestBody Consult consult){
        return consultService.updateStatusByClaim(consult);
    }
    /*
    根据id查询预定信息
     */
    @GetMapping("/findConsultById")
    public JsonResult findConsultById(Integer consult_id){
        return consultService.findConsultById(consult_id);
    }
    /*
    根据用户id查询预订单信息
     */
    @GetMapping("/findConsultByUserId")
    public JsonResult findConsultByUserId(Integer appUserId){
        return consultService.findConsultByUserId(appUserId);
    }

}


